<script setup>
import {onMounted, ref} from 'vue';
import axios from "axios";

const searchKeyword = ref('');

const handleSearch = () => {
  console.log('搜索关键词：', searchKeyword.value);
  // 这里可以添加实际的搜索逻辑
};
const bookType = ref([])
//获取后端书籍分类用
onMounted(()=>{
  axios.get("/bookType").then(res=>{
    bookType.value = res.data.obj;
  })
})


</script>

<template>
  <header class="header">
    <div class="logo-and-search">
      <div class="logo-section">
        <img src="../assets/logo.png" alt="蜗牛书城 logo" class="logo">
        <div>
          <h1>蜗牛书城</h1>
          <p>www.woniuxy.com</p>
        </div>
      </div>
      <div class="search-section">
        <el-input v-model="searchKeyword" placeholder="请输入搜索关键字" clearable prefix-icon="Search" size="large"></el-input>
        <el-button @click="handleSearch" icon="Search" size="large">搜索</el-button>
      </div>
    </div>
    <div class="user-actions">
      <router-link to="/login">
        <el-button size="large">登录</el-button>
      </router-link>
      <router-link to="/register">
        <el-button size="large">注册</el-button>
      </router-link>
      <router-link to="/home">
        <el-button size="large">首页</el-button>
      </router-link>
      <router-link to="/personal-center">
        <el-button size="large">个人中心</el-button>
      </router-link>
      <router-link to="/shopping-cart">
        <el-button size="large">购物车</el-button>
      </router-link>
      <router-link to="/my-orders">
        <el-button size="large">我的订单</el-button>
      </router-link>
      <router-link to="/logout">
        <el-button size="large">退出</el-button>
      </router-link>
      <el-button size="large" disabled>欢迎您</el-button>
    </div>
  </header>
  <nav class="nav">
    <router-link to="/hot-list" class="nav-item">热销榜</router-link>
    <router-link v-for="type in bookType"  :to="{path:'/getBookTid',query:{id:type.id}}" class="nav-item">{{type.name}}</router-link>
  </nav>
</template>



<style scoped>
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 40px;
  background-color: #1e1e1e;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.logo-and-search {
  display: flex;
  align-items: center;
}

.logo-section {
  display: flex;
  align-items: center;
  margin-right: 40px;
}

.logo {
  width: 60px;
  height: 60px;
  margin-right: 15px;
  border-radius: 8px;
}

.logo-section h1 {
  font-size: 24px;
  color: #fff;
  margin-bottom: 5px;
}

.logo-section p {
  font-size: 14px;
  color: #a0a0a0;
}

.search-section {
  display: flex;
  align-items: center;
}

.search-section .el-input {
  width: 300px;
  margin-right: 15px;
  background-color: #2a2a2a;
  border: none;
  color: #e0e0e0;
  border-radius: 20px;
}

.search-section .el-input__wrapper {
  background-color: #2a2a2a;
  border: none;
}

.search-section .el-button {
  background-color: #007bff;
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 8px 20px;
  transition: background-color 0.3s ease;
}

.search-section .el-button:hover {
  background-color: #0056b3;
}

.user-actions {
  display: flex;
}

.user-actions .el-button {
  margin-left: 15px;
  background-color: #2a2a2a;
  color: #e0e0e0;
  border: none;
  border-radius: 20px;
  padding: 8px 20px;
  transition: background-color 0.3s ease;
}

.user-actions .el-button:hover {
  background-color: #3a3a3a;
}

.user-actions .el-button:disabled {
  background-color: #2a2a2a;
  color: #a0a0a0;
  cursor: not-allowed;
}

.nav {
  display: flex;
  justify-content: center;
  background-color: #2a2a2a;
  padding: 15px 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.nav-item {
  margin: 0 15px;
  text-decoration: none;
  color: #e0e0e0;
  font-size: 16px;
  transition: color 0.3s ease;
}

.nav-item:hover {
  color: #007bff;
}
</style>